package ro.hex.remocadm;

/**
 * Class representing a channel.<br/>
 * Used when reading the channels from configuration file and populating
 * the channelList variable in GUI.java.
 * 
 * @author Iulian Virtejanu
 */
public class V4L2Channel implements Channel{
    private String vlcChannelFreq;
    private String name;

    public V4L2Channel(String vlcChannelFreq, String name) {
        this.vlcChannelFreq = vlcChannelFreq;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVlcChannel() {
        return vlcChannelFreq;
    }

    public void setVlcChannel(String vlcChannel) {
        this.vlcChannelFreq = vlcChannel;
    }

    @Override
    public String toString() {
        return getName();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final V4L2Channel other = (V4L2Channel) obj;
        if ((this.vlcChannelFreq == null) ? (other.vlcChannelFreq != null) : !this.vlcChannelFreq.equals(other.vlcChannelFreq)) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

    public static V4L2Channel parseChannel(String line) {

        // remove the marker of the channel
        line = line.substring("vl.".length());

        int indexOfPoint = line.indexOf('.');
        int indexOfEquals = line.indexOf('=');

        String freq = line.substring(indexOfPoint + 1, indexOfEquals);
        String nam = line.substring(indexOfEquals + 1);

        return new V4L2Channel(freq, nam);
    }

}
